package qc;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;

import org.quickconnect.ControlObject;

import ui.MainFrame;

import com.mysql.jdbc.Connection;

public class UnlockServerBCO implements ControlObject{

	@Override
	public Object handleIt(ArrayList<Object> arg0) {
		HashMap params = (HashMap) arg0.get(arg0.size()-1);
		String password = (String) params.get("password");
		Connection con = (Connection)MainFrame.mainFrame.getController().getConnectionPool().getConnection();
		java.sql.PreparedStatement select = null;
		ResultSet results = null;
		
		try {
			select = con.prepareStatement("SELECT UserID FROM User WHERE UserName = 'MasterAdmin' AND UserPass = ?");
			select.setString(1, password);
			results = select.executeQuery();
			if (results.next()) {
				params.put("success", "true");
			}
			else {
				params.put("success", "false");
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		MainFrame.mainFrame.getController().getConnectionPool().returnConnection(con);
		return params;
	}

}
